// pages/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_info: "",
    hasUserInfo: false,

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var that = this
    console.log(res, '88888888888888888888')
    if (res.from === 'button') {
      console.log("来自页面内转发按钮");
      console.log(res.target);
    } else {
      var pages = getCurrentPages() //获取加载的页面
      var currentPage = pages[pages.length - 1] //获取当前页面的对象
      var url = currentPage.route //当前页面url
      console.log(url, '888888888888')
      console.log("来自右上角转发菜单")
      return {
        title: '分享至朋友圈',
        path: url,
        success: (res) => {
          console.log("转发成功", res);
        },
        fail: (res) => {
          console.log("转发失败", res);
        }
      }
    }

  },


  get_user_info() {




    wx.getUserProfile({
      desc: '登录',
      success: (res) => {
        console.log(res);
        this.setData({
          user_info: res.userInfo,
          hasUserInfo: true
        })
        let nick_name = res.userInfo.nickName
        let head = res.userInfo.avatarUrl

        wx.login({
          success: res => {
            wx.request({
              url: 'https://vip.join.ink/api/getweixinOpenid',
              method: "POST",
              data: {
                code: res.code
              },
              method: "POST",
              success: res => {
                console.log(res);
                wx.request({
                  url: 'https://vip.join.ink/api/login',
                  method: "POST",
                  data: {
                    openid: res.data.openid,
                    head,
                    nick_name
                  },
                  success: result => {
                    console.log(result.data.token);
                    wx.setStorageSync('user_id', result.data.user.id);
                    console.log(result.data.user.id, '99999999999999999999999999999999999999999999999999')

                    wx.setStorage({
                      data: result.data.token,
                      key: 'token',
                      success: (e) => {
                        console.log(e);


                      }
                    })
                    if (getApp().globalData.is_login_url) {
                      wx.redirectTo({
                        url: getApp().globalData.is_login_url
                      })

                    }
                  }
                })
              }
            })
          }
        })
      }
    })








  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})